package com.googlecode.garbagecan.perf4jstudy;

import java.io.Reader;
import java.io.StringReader;

import org.perf4j.LogParser;
import org.perf4j.StopWatch;
import org.perf4j.helpers.GroupedTimingStatisticsTextFormatter;

public class Test1 {
	public static void main(String[] args) throws Exception {
		test1();
		test2();
	}

	private static void test1() throws Exception {
		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < 5; i++) {
			StopWatch stopWatch = new StopWatch();
			Thread.sleep(1000);
			stopWatch.stop("test");
			sb.append(stopWatch.toString()).append("\n");
		}
		System.out.println(sb.toString());
	}

	private static void test2() throws Exception {
		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < 5; i++) {
			StopWatch stopWatch = new StopWatch();
			Thread.sleep(1000);
			stopWatch.stop("test");
			sb.append(stopWatch.toString()).append("\n");
		}
		Reader reader = new StringReader(sb.toString());
		LogParser logParser = new LogParser(reader, System.out, null, 10 * 1000, true, new GroupedTimingStatisticsTextFormatter());
		logParser.parseLog();
	}
}
